主题
销毁客户端 - TcpClientDestroy
函数简介
销毁TCP客户端(会自动断开连接)。
接口名称
TcpClientDestroyDLL调用
c
int32_t TcpClientDestroy(int64_t instance, int64_t client_handle);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| client_handle | 长整数型 | 客户端句柄。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long client = ola.TcpClientCreate(nullptr, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000);
// 退出前销毁,会自动断开连接
int ret = ola.TcpClientDestroy(client);
ola.TcpClientDestroy(client);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
long client = ola.TcpClientCreate(null, 0, 1);
if (client != 0)
{
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000);
int ret = ola.TcpClientDestroy(client);
ola.TcpClientDestroy(client);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
client = ola.TcpClientCreate(None, 0, 1)
if client:
# enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000)
ret = ola.TcpClientDestroy(client)
ola.TcpClientDestroy(client)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long client = ola.TcpClientCreate(null, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000);
int ret = ola.TcpClientDestroy(client);
ola.TcpClientDestroy(client);
}go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
long client = ola.TcpClientCreate(nil, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000)
ret := ola.TcpClientDestroy(client)
ola.TcpClientDestroy(client);
}rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
long client = ola.TcpClientCreate(None, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.tcp_client_connect(&client, "127.0.0.1", 9000);
let ret = ola.tcp_client_destroy(&client);
ola.TcpClientDestroy(client);
}cpp
var ola = com("OlaPlug.OlaSoft")
long client = ola.TcpClientCreate(0, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000)
var ret = ola.TcpClientDestroy(client)
ola.TcpClientDestroy(client);
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
client = ola.TcpClientCreate(0, 0, 1)
If client <> 0 Then
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000)
ret = ola.TcpClientDestroy(client)
ola.TcpClientDestroy(client)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
client = ola.TcpClientCreate (0, 0, 1)
.如果真 (client ≠ 0)
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect (client, "127.0.0.1", 9000)
ret = ola.TcpClientDestroy (client)
ola.TcpClientDestroy (client)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
long client = ola.TcpClientCreate(null, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000);
var ret = ola.TcpClientDestroy(client);
ola.TcpClientDestroy(client);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
long client = ola.TcpClientCreate(0, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000)
整数 ret = ola.TcpClientDestroy(client)
ola.TcpClientDestroy(client);
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long client = ola.TcpClientCreate(nullptr, 0, 1);
if (client != 0) {
// enable_packet_protocol=1 启用分包协议
ola.TcpClientConnect(client, "127.0.0.1", 9000);
int ret = ola.TcpClientDestroy(client);
ola.TcpClientDestroy(client);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long client = TcpClientCreate(instance, 0, instance, 1);
if (client != 0) {
TcpClientConnect(instance, client, "127.0.0.1", 9000);
TcpClientDestroy(instance, client);
TcpClientDestroy(instance, client);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long TcpClientCreate(long ola, long callback, long user_data, int enable_packet_protocol);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int TcpClientDestroy(long ola, long client_handle);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int TcpClientConnect(long ola, long client_handle, string host, int port);
long instance = CreateCOLAPlugInterFace();
long client = TcpClientCreate(instance, 0, instance, 1);
if (client != 0) {
TcpClientConnect(instance, client, "127.0.0.1", 9000);
TcpClientDestroy(instance, client);
TcpClientDestroy(instance, client);
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
client = ola.TcpClientCreate(instance, 0, instance, 1)
if client:
ola.TcpClientConnect(instance, client, "127.0.0.1", 9000);
ola.TcpClientDestroy(instance, client);
ola.TcpClientDestroy(instance, client)返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 整数型,1 成功,0 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 销毁前会自动断开连接 | 销毁前会自动断开连接。 |
| 销毁后 | 销毁后,客户端句柄失效,不可再使用。 |
| 销毁会释放所有相关资源 | 销毁会释放所有相关资源。 |
| 建议在程序退出前销毁所有客户端 | 建议在程序退出前销毁所有客户端。 |
| 销毁后不会再触发回调 | 销毁后不会再触发回调。 |
